/*jq    */
/*--------------------下拉菜单----------------------*/
$(function () {
  /*  $(".drop_select1_menu ul li").click(function () {

        $("#sel").html($(this).html());

    });*/
    //添加window滚动
    $(document).click(function(event) {
        var targetClass = event.target.className;
        if(targetClass =="show_info" || targetClass == "select1" || targetClass == "menu_select") {
            if(document.getElementById('xiadiv1').style.display=="block"){
               $(".select1").unbind("click")
             }else{
                $("#drop_down_select1_id").toggleClass('active');
             }
        } else {
            $("#drop_down_select1_id").removeClass('active');
        }
    });
    $(window).scroll(function () {
        $('#cover').hide();
        $("#drop_down_select1_id").hide();
    });

    $(".drop_down_menu1 ul li").click(function () {
        $("#sel1").html($(this).html());
    });
    //添加window滚动
    $(window).scroll(function () {

        $("#drop_down_select1_id").hide();
    });

    $(".drop_down_menu3 ul li").click(function () {
        $("#sel3").html($(this).html());
    });
    //添加window滚动
    $(window).scroll(function () {

        $("#drop_down_menu_id3").hide();
    });

    $('.menu').click(function () {
        $('.option').toggleClass('pop-out');
    });

    $("#menu1 a").click(function (event) {
        if (!$('.option').hasClass('pop-out')) {
            event.preventDefault();
        }
    });


    $('#user_photo').change(function () {
        lrz(this.files[0],{width:400})
            .then(function (rst) {
                // 处理成功会执行
                var path = rst.base64.replace('data:image/jpeg;base64,','');
                $('#user_photo_show').attr('src',rst.base64);
                $('#user_photo_input').val(rst.base64);
            })
            .catch(function (err) {
                // 处理失败会执行
            })
            .always(function () {
                // 不管是成功失败，都会执行
            });
    });

    $('#goods_photo').change(function () {
        lrz(this.files[0],{width:400})
            .then(function (rst) {
                // 处理成功会执行
                var path = rst.base64.replace('data:image/jpeg;base64,','');
                $('#goods_photo_show').attr('src',rst.base64);
                $('#goods_photo_input').val(rst.base64);
                $('#goods_photo1_bar').show();
            })
            .catch(function (err) {
                // 处理失败会执行
            })
            .always(function () {
                // 不管是成功失败，都会执行
            });
    });
    $('#goods_photo1').change(function () {
        lrz(this.files[0],{width:400})
            .then(function (rst) {
                // 处理成功会执行
                var path = rst.base64.replace('data:image/jpeg;base64,','');
                $('#goods_photo_show1').attr('src',rst.base64);
                $('#goods_photo1_input').val(rst.base64);
                $('#goods_photo2_bar').show();
            })
            .catch(function (err) {
                // 处理失败会执行
            })
            .always(function () {
                // 不管是成功失败，都会执行
            });
    });
    $('#goods_photo2').change(function () {
        lrz(this.files[0],{width:400})
            .then(function (rst) {
                // 处理成功会执行
                var path = rst.base64.replace('data:image/jpeg;base64,','');
                $('#goods_photo_show2').attr('src',rst.base64);
                $('#goods_photo2_input').val(rst.base64);
            })
            .catch(function (err) {
                // 处理失败会执行
            })
            .always(function () {
                // 不管是成功失败，都会执行
            });
    });

    $('.publish_needs').click(function() {
        var title = document.getElementById("title").value;
        var memo = document.getElementById("memo").value;
        var money = document.getElementById("money").value;
        if (cate == 10) {
            alert('请选择信息类别');
            return false;}
        if (!check('title')) {return false;}
        if (!check('memo')) {return false;}
        if (!check('money')) {return false;}
        
        image_path = '/zgc/Public/images/uploading.png';
        
        /* 提交的后执行*/
        var data = {
            id: $('#goods_id').val(),
            user_judge: 'need',
            goods_sort: cate,
            goods_title: $('#title').val(),
            goods_intro: $('#memo').val(),
            price: $('#money').val(),
            tel: $('#tel').val(),
            goods_photo: $('#goods_photo_input').val(),
            goods_photo1: $('#goods_photo1_input').val(),
            goods_photo2: $('#goods_photo2_input').val(),
            linkman:$('#linkman').val()
        };

        $.post('/zgc/index.php/Home/Goods/addPublish', data, function (msg) {
            if (msg == '0') {
                alert('添加失败，请稍候重试！');
            } else {
                clear();
                document.getElementById("title").value = '';
                document.getElementById("memo").value = '';
                document.getElementById("money").value = '';
                document.getElementById("tel").value = '';
                cate = 10;
                $('#goods_photo_show').attr('src',image_path);
                $('#goods_photo_show1').attr('src',image_path);
                $('#goods_photo_show2').attr('src',image_path);
                $('#goods_photo_input').val('');
                $('#goods_photo1_input').val('');
                $('#goods_photo2_input').val('');
                $('#goods_photo1_bar').hide();
                $('#goods_photo2_bar').hide();
                $('#vendor_name').val('');
                release1();
            }
        });
    });

    $('.publish_server').click(function() {
        var name = $('#user_name').val();
        var title = document.getElementById("title").value;
        var memo = document.getElementById("memo").value;
        var tel = document.getElementById("tel").value;
        var money = document.getElementById("money").value;
        var address = document.getElementById("address").value;
        var linkman = document.getElementById("linkman").value;
        var vendor_name = document.getElementById("vendor_name").value;
        if (cate == 10) {
            alert('请选择信息类别');
            return false;}
        if (!check('title')) {return false;}
        if (!check('memo')) {return false;}
        if (!check('money')) {return false;}
        if (!check('tel')) {return false;}
        if (!check('address')) {return false;}
        if (!check('linkman')) {return false;}
        if (!check('vendor_name')) {return false;}
               

        image_path = '/zgc/Public/images/uploading.png';
       
        /* 提交的后执行*/

        var data = {
            id: $('#goods_id').val(),
            user_judge: 'serve',
            goods_sort: cate,
            goods_title: $('#title').val(),
            goods_intro: $('#memo').val(),
            price: $('#money').val(),
            tel: $('#tel').val(),
            addr: $('#address').val(),
            goods_photo: $('#goods_photo_input').val(),
            goods_photo1: $('#goods_photo1_input').val(),
            goods_photo2: $('#goods_photo2_input').val(),
            linkman:$('#linkman').val(),
            vendor_type:vendor_type,
            vendor_name:$('#vendor_name').val()
        };
        console.log(data);
        $.post('/zgc/index.php/Home/Goods/addPublish', data, function (msg) {
            if (msg == '0') {
                alert('添加失败，请稍候重试！');
            } else {
                // window.location = msg;
                clear();
                document.getElementById("title").value = '';
                document.getElementById("memo").value = '';
                document.getElementById("money").value = '';
                document.getElementById("tel").value = '';
                document.getElementById("address").value = '';
                document.getElementById("linkman").value = '';
                document.getElementById("tel").value = '';
                $('#vendor_name').val(name);
                vendor(1);
                cate = 10;
                $('#goods_photo_show').attr('src',image_path);
                $('#goods_photo_show1').attr('src',image_path);
                $('#goods_photo_show2').attr('src',image_path);
                $('#goods_photo_input').val('');
                $('#goods_photo1_input').val('');
                $('#goods_photo2_input').val('');
                $('#goods_photo1_bar').hide();
                $('#goods_photo2_bar').hide();
                release1();
            }
        });
    });

    
    $('#agreement').click(function () {
        if($(this).is(':checked') == true){
            $('#login_btn').bind('click',function() {
                if (!(/^\d{4}$/.test(document.getElementById("verify_num1").value))) {
                    document.getElementById("verify_num1").style.border = "#58749c 2px solid";
                    return false;
                } else {
                    $(this).text('正在登陆,请稍后...');
                    $(this).attr('disabled',true);
                    param = {
                        phone: $('#phone').val(),
                        num_v: $('#verify_num1').val()
                    };
                    $.ajax({
                        type: 'post',
                        data: param,
                        dataType: 'text',
                        url: '/zgc/index.php/Home/User/checkVerify',
                        success: function (resp) {
                            if (resp == 0) {
                                alert('验证码错误')
                                $(this).removeAttr('disabled');

                            } else {
                                if (resp == 1) {
                                    window.location = '/zgc/index.php/Home/User/personal_data';
                                } else {
                                    window.location = resp;
                                    // alert('登录成功');
                                }
                            }

                        }
                    });

                    document.getElementById("verify_num1").style.border = "none";
                    return true;
                }
            });
        }else{
            $('.login_btn').unbind('click');
        }
    });
});

//首页下拉刷新
var j = 0;
var lock = 1;
var flag = 1;

function getIndexData(x, y) {
    if (lock == 1 && flag == 1) {
        lock = 0;
        if (j != 0) {
            $('.load_more').show().html('正在加载');
        }
        var data = {};
        if (y == 'search') {
            data = {
                module: jx,
                cate: jx1,
                search: $('#searchbar').val(),
                search_option: $('#search_option').val(),
                page: x
            }
        } else {
            data = {
                module: jx,
                cate: jx1,
                page: x
            }
        }
        
        $.post('/zgc/index.php/Home/Index/getData', data, function (msg) {
            
            if (msg.state == -1) {
                flag = 0;
                if (j==0) {
                    $('.load_more').show().html('暂无搜索内容');
                }else{
                   $('.load_more').show().html('已经到底了'); 
               };                
            } else {
                var html = '';
                var obj = {};
                for (var i = 0; i < msg.length; i++) {
                    obj = msg[i];
                    // console.log(obj)
                    if(!obj.goods_photo){
                        obj.goods_photo = '/zgc/Public/images/default01.png';
                    }
                    html += "<div class='content'><a href='/zgc/index.php/Home/Goods/" + obj.user_judge + "_detail/id/" + obj.id + "'><div class='content_photo'><img style='width:100%; height:60px;' src='" + obj.goods_photo + "'></div><div class='content_text'><h1>" + obj.goods_title + "</h1><span class='budget_price'>预算：" + obj.price + "元</span><span class='"+obj.user_judge+"_icon'>"+obj.category_name+"</span><span class='browse_num'>" + obj.browse_num + "人浏览</span></div><div class='clearfix'></div></a></div>";
                }
                $('.load_more').html('');
                $('.content_box').append(html);
                $('#t12').show();
                $('#content_all').show();
                $('#xiadiv1').hide();
                $('#alldiv').hide();
                j++;
                lock = 1;
            }
        }, 'json')
    }
}

//检测联系人的电话
function checkTel(){
    
    var tel = document.getElementById("tel").value;
    if (!check('tel')) {
        alert('请填写电话');
    }
}

//搜索框
$(document).ready(function(){
  $(".search input").focus(function(){
    $(".search input").css({"text-align":"left","padding-left":"6px"});
  });
});

$(document).ready(function(){
  $(".search input").blur(function(){
    $(".search input").css({"text-align":"center","padding-left":"0px"});
});
});

//查看其他用户跳转去向
function goUserList(){

    var sess_id = $('#sess_id').val();
    var user_id = $('#user_id').val();
    if (sess_id){
        window.location = '/zgc/index.php/Home/Goods/user_publish_list/user_id/'+user_id;
    }else{
        var data = {
        user_id: user_id
        };
        $.post('/zgc/index.php/Home/Goods/save_needurl', data, function (msg) {
        window.location = '/zgc/index.php/Home/User/login';

        }, 'text');
    }
    
}

//显示大图

function showImg(outdiv,indiv,bigimg,thiselement){  
    var winW = $(window).width();  
    var winH = $(window).height();  
    var src = $(thiselement).attr('src');  
    $(bigimg).attr("src",src);  
    $("<img/>").attr("src",src).load(function(){  
        var imgW = this.width;   
        var imgH = this.height;  
        var scale= imgW/imgH;  
        if( imgW > winW ){  
            $(bigimg).css("width","100%").css("height","auto");  
            imgH = winW/scale;  
            var h=(winH-imgH)/2;              
            $(indiv).css({"left":0,"top":h});  
        }else{          
            $(bigimg).css("width",imgW+'px').css("height",imgH+'px');  
            var w=(winW-imgW)/2;  
            var h=(winH-imgH)/2;        
            $(indiv).css({"left":w,"top":h});  
        }  
                
        $(outdiv).fadeIn("fast");  
        $(outdiv).click(function(){  
            $(this).fadeOut("fast");  
        });                               
    });  
}

$(document).ready(function(){
$('.imgclass').click(function(){  
    var thiselement=$(this);  
    showImg("#outdiv",".indiv","#bigimg",thiselement);  
});  
});   

// 处理商户类型点击
var vendor_type = '公司';
function vendor(x){
    
    //将商户名称改变
     if (x == 1) {
        $('.msg_vendor_name h1').html('公司名称');
        vendor_type = '公司';
     }else if(x == 2){
        $('.msg_vendor_name h1').html('团体名称');
        vendor_type = '团体';
     }else{
        $('.msg_vendor_name h1').html('商户名称');
        vendor_type = '个人';
     };
    clear1();
    document.getElementById('vendor_type' + x).style.background = "#58749c";
    document.getElementById('vendor_type' + x).style.color = "#ffffff";
}

function clear1() {

    var liarr = document.getElementById("msg_vendor_type_ul").getElementsByTagName("li");
    for (var i = 0; i < liarr.length; i++) {
        liarr[i].style.background = "#ffffff";
        liarr[i].style.color = "#666666";
    }
}
function guan1() {

    document.getElementById('t12').style.display = 'block';
    document.getElementById('content_all').style.display = 'block';
    document.getElementById('xiadiv1').style.display = 'none';
    document.getElementById('alldiv').style.display = 'none';

    $('.content_box').html('');
    $('.load_more').html('');
    j = 0;
    lock = 1;
    flag = 1;
    getIndexData(0,'index');

    document.getElementById('search_box').style.display='block';
}


// JavaScript Document
/*-------顶部菜单列表横向动-------*/
/*var myScroll;
 function loaded () {
 myScroll = new IScroll('#wrapper', { eventPassthrough: true, scrollX: true, scrollY: false, preventDefault: false });
 }
 */

/*---------点击黑色背景时关闭发布--------*/
function offrelease() {
    document.getElementById("bgback").style.display = "none";
    document.getElementById("popup_btn_box1").style.display = "none";
    //document.getElementById("release1").style.display="none";
    //document.getElementById("release2").style.display="none";

}

/*-------显示和隐藏下拉菜单 ----------*/

function showdropmenu(id)
{
    if(document.getElementById(id).style.display=="block")
    {    
        document.getElementById(id).style.display="none";
    }else{

        document.getElementById(id).style.display="block";      
    }  
}


function menuhide() {
    $("#drop_down_select1_id").hide();
}

function menuhide1() {
    $("#drop_down_menu_id1").hide();
    $("#drop_down_menu_id3").hide();
}


var searchInfo = 1;
function listMenu1(x, y) {
    
    $('#drop_down_select1_id').hide();
    $('#cover').hide();
    searchInfo = x;

    $('#search_option').val(x);
    $('.show_info').html(y);

}

var self_mod = 10;
var self_cate = 'all';

function getPublishData() {
    alert(self_cate);
    alert(self_mod);
    var data = {
        sel: self_mod,
        sel1: self_cate,
    }
    $.post('/zgc/index.php/Home/Goods/getData', data, function (msg) {
        for (var i = 0; i < msg.length; i++) {
            var obj = msg[i];
            $('.content_box').html("<div class='content'><a href='/zgc/index.php/Home/Goods/my_detail/id/" + obj.id + "'><div class='content_photo'><img src='/zgc/Public/images/content_pictrue1.png'></div><div class='content_text'><h1>" + obj.goods_title + "</h1><span class='budget_price'>价格：" + obj.price + "元</span><span class='browse_num'>" + obj.browse_num + "人浏览</span></div><div class='clearfix'></div></a></div>");
        }

    }, 'json')
}
function listMenu(m) {
    self_mod = m;
    document.getElementById('drop_down_menu_id1').style.display = "none";
    document.getElementById('drop_down_menu_id3').style.display = "none";

    alert(self_cate);
    alert(self_mod);
    getPublishData();
}
function listMenu2(n) {
    self_cate = n;
    document.getElementById('drop_down_menu_id1').style.display = "none";
    document.getElementById('drop_down_menu_id3').style.display = "none";

    getPublishData();
}


/*
 function display_other1(){
 document.getElementById('drop_down_menu_id3').style.display="none";
 }
 function display_other3(){
 document.getElementById('drop_down_menu_id1').style.display="none";
 }

 */
/*---------------------服务发布判断----------- */
function submitOK() {
    var title = document.getElementById("title").value;
    var memo = document.getElementById("memo").value;
    var money = document.getElementById("money").value;
    var tel = document.getElementById("tel").value;
    var address = document.getElementById("address").value;

    if (!check('title')) {
        return false;
    }
    if (!check('memo')) {
        return false;
    }

    if (!check('money')) {
        return false;
    }
    if (!check('tel')) {
        return false;
    }
    if (!check('address')) {
        return false;
    }

    release1();
}


function submitOK11() {
    
    var title = document.getElementById("title").value;
        var memo = document.getElementById("memo").value;
        var money = document.getElementById("money").value;
        if (cate == 10) {
            alert('请选择信息类别');
            return false;}
        if (!check('title')) {return false;}
        if (!check('memo')) {return false;}
        if (!check('money')) {return false;}
              
        /* 提交的后执行*/
        var data = {
            id: $('#goods_id').val(),
            user_judge: 'need',
            goods_sort: cate,
            goods_title: $('#title').val(),
            goods_intro: $('#memo').val(),
            price: $('#money').val(),
            tel: $('#tel').val(),
            goods_photo: $('#goods_photo_input').val(),
            goods_photo1: $('#goods_photo1_input').val(),
            goods_photo2: $('#goods_photo2_input').val(),
            linkman:$('#linkman').val()
        };


    $.post('/zgc/index.php/Home/Goods/addPublish', data, function (msg) {
        if (msg == '0') {
            alert('修改失败，请稍候重试！');

        } else {
            window.location = msg;
        }
    });
}

function submitOK12() {
    
        var name = $('#user_name').val();
        var title = document.getElementById("title").value;
        var memo = document.getElementById("memo").value;
        var tel = document.getElementById("tel").value;
        var money = document.getElementById("money").value;
        var address = document.getElementById("address").value;
        var linkman = document.getElementById("linkman").value;
        var vendor_name = document.getElementById("vendor_name").value;
        if (cate == 10) {
            alert('请选择信息类别');
            return false;}
        if (!check('title')) {return false;}
        if (!check('memo')) {return false;}
        if (!check('money')) {return false;}
        if (!check('tel')) {return false;}
        if (!check('address')) {return false;}
        if (!check('linkman')) {return false;}
        if (!check('vendor_name')) {return false;}

        var data = {
            id: $('#goods_id').val(),
            user_judge: 'serve',
            goods_sort: cate,
            goods_title: $('#title').val(),
            goods_intro: $('#memo').val(),
            price: $('#money').val(),
            tel: $('#tel').val(),
            addr: $('#address').val(),
            goods_photo: $('#goods_photo_input').val(),
            goods_photo1: $('#goods_photo1_input').val(),
            goods_photo2: $('#goods_photo2_input').val(),
            linkman:$('#linkman').val(),
            vendor_type:vendor_type,
            vendor_name:$('#vendor_name').val()
        };


    $.post('/zgc/index.php/Home/Goods/addPublish', data, function (msg) {
        if (msg == '0') {
            alert('修改失败，请稍候重试！');

        } else {
            window.location = msg;
        }
    });
}

/*---------点击取消发布时关闭发布--------*/
// function popup_no() {
//     document.getElementById("bgback").style.display = "none";
//     document.getElementById("popup_btn_box1").style.display = "none";
//     //document.getElementById("release1").style.display="none";
//     //document.getElementById("release2").style.display="none";
//     window.location = need_url;

// }





function check(obj) {
    if (document.getElementById(obj).value == "") {
        document.getElementById(obj).style.border = "2px solid #58749C";
        document.getElementById(obj).focus();

    }
    else {
        document.getElementById(obj).style.border = "0px";

    }
    return document.getElementById(obj).value;
}

var cate = 10;
function category(id) {
    cate = id;
    clear();
    document.getElementById('sort' + id).style.background = "#58749c";
    document.getElementById('sort' + id).style.color = "#ffffff";

}
function clear() {

    var liarr = document.getElementById("msgsort").getElementsByTagName("li");
    for (var i = 0; i < liarr.length; i++) {
        liarr[i].style.background = "#ffffff";
        liarr[i].style.color = "#666666";
    }
}


/*判断字符串的长短*/
function lenthnum() {
    var lenstr = 200;
    var text = $("#memo").val();
    var counter = text.length;
    $("#zinumjia").text(counter);
    $("#zinumjian").text(lenstr - counter);
    if (counter >= lenstr) {
        $("#zinumjia").text(lenstr);
        $("#zinumjian").text(0);
        $("#memo").val(text.substr(0, lenstr));

    }
}

/*----------------------首页导航-------------------------*/
var te1 = 1;
var te2 = 1;
var te3 = 1;
var te4 = 1;

/* 判断是开是关*/

var jia = "";//价格
var tiaojian = "";
//开
function kai(id) {
    document.getElementById('t12').style.display = 'none';
    document.getElementById('content_all').style.display = 'none';
    $('#xiadiv' + id).show(0, kaiall);
}

//关
function guan(id) {
    document.getElementById('tzi' + id).style.color = "#666666";
    // document.getElementById('xia'+id).innerHTML="<img src=images/prom_more_down.png>";
    if (id == 1)//当关掉1时
    {
        te1 = 1;
    }
    if (id == 2)//当关掉2时
    {
        te2 = 1;
    }
    if (id == 3)//当关掉3时
    {
        te3 = 1;
    }
    if (id == 4)//当关掉4时
    {
        te4 = 1;
    }


}


//底部背景黑色开
function kaiall() {
    document.getElementById('alldiv').style.display = 'block';
     document.getElementById('search_box').style.display='none';
}

//全关
function guanall() {
    try {
        guan(1);
        guan(2);
        guan(3);
        guan(4);
        document.getElementById('alldiv').style.display = 'none';

    }
    catch (e) {
    }
}


var tnum = 1;//当前是点的哪个
function divshow1() {

    if (tnum == 1)//当前是第一个开了
    {
        if (te1 == 1) {
            kai(1);
            te1 = 2;//通知是开的
        }
        else {
            te1 = 1;
            guanall();

        }
    }
    else //当前不是第一个
    {

        guan(tnum);
        kai(1);
        te1 = 2;//通知是开的
    }
    tnum = 1;
}

var jx = 10;
var jx1 = 'all';

function jiaxuan1(n) {

    jx1 = n;
    if (tiaojian == "" || tiaojian == "all") {
        document.getElementById("all").style.background = "#fff";
    }
    if (tiaojian == "need") {
        document.getElementById("need").style.background = "#fff";
    }
    if (tiaojian == "serve") {
        document.getElementById("serve").style.background = "#fff";
    }

    tiaojian = n;
    if (tiaojian == "all") {
        document.getElementById("all").style.background = "#eee";
    }
    if (tiaojian == "need") {

        document.getElementById("need").style.background = "#eee";

    }
    if (tiaojian == "serve") {
        document.getElementById("serve").style.background = "#eee";
    }
}

function jiaxuan(m) {

    jx = m;

    if (jia == "" || jia == "10") {
        document.getElementById("more_select1").style.background = "#fff";
    }
    if (jia == "1") {
        document.getElementById("more_select2").style.background = "#ffffff";
    }
    if (jia == "2") {
        document.getElementById("more_select3").style.background = "#ffffff";
    }
    if (jia == "4") {
        document.getElementById("more_select4").style.background = "#ffffff";
    }
    if (jia == "5") {
        document.getElementById("more_select5").style.background = "#ffffff";
    }
    if (jia == "6") {
        document.getElementById("more_select6").style.background = "#ffffff";
    }
    if (jia == "3") {

        document.getElementById("more_select7").style.background = "#ffffff";

    }
    if (jia == "7") {

        document.getElementById("more_select8").style.background = "#ffffff";

    }
    if (jia == "8") {
        document.getElementById("more_select9").style.background = "#ffffff";
    }


    //------------------

    jia = m;

    var showm = "";
    if (m == '10') {
        showm = "热门";
        document.getElementById("more_select1").style.background = "#eee";
        jia = "";

    }
    if (m == '1') {
        showm = "智造中心";
        document.getElementById("more_select2").style.background = "#eee";
    }

    if (m == '2') {
        showm = "产品设计";
        document.getElementById("more_select3").style.background = "#eee";
    }
    if (m == '4') {
        showm = "检测认证";
        document.getElementById("more_select4").style.background = "#eee";
    }
    if (m == '5') {
        showm = "产品中试";
        document.getElementById("more_select5").style.background = "#eee";
    }
    if (m == '6') {
        showm = "推广营销";
        document.getElementById("more_select6").style.background = "#eee";
    }
    if (m == '3') {
        showm = "技术研发";
        document.getElementById("more_select7").style.background = "#eee";
    }
    if (m == '7') {
        showm = "协同服务";
        document.getElementById("more_select8").style.background = "#eee";
    }
    if (m == '8') {
        showm = "其他";
        document.getElementById("more_select9").style.background = "#eee";
    }
    document.getElementById('tzi1').innerHTML = showm;
    guan(1);
    solist();
}

function gogocar(id) {
    alert(id);

}
function reash() {
///刷新
    location.reload()

}
function solist() {
}

/*--------------------验证手机号---------------*/
function validatemobile(mobile) {
    var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
    if (mobile.length == 0) {
        alert('请输入手机号码！');
        document.getElementById("phone").focus();
        return false;
    }
    if (mobile.length != 11) {
        alert('请输入有效的手机号码！');
        document.getElementById("phone").focus();

        return false;
    }


    if (!myreg.test(mobile)) {
        alert('请输入有效的手机号码！');
        document.getElementById("phone").focus();

        return false;
    }
}

/*----------------获取手机验证码--------------*/



/*------------验证码是否正确--------------*/
function validatemobile1(mobile1) {
    if (mobile1.length == 0) {
        alert('请输入手机验证码！');
        document.getElementById("verify_num1").focus();
        return false;
    }
    if (mobile1.length != 6) {
        alert('请输入有效的手机验证码！');
        document.getElementById("verify_num1").focus();

        return false;
    }

    var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
    if (!myreg.test(mobile)) {
        alert('请输入有效的手机验证码！');
        document.getElementById("verify_num1").focus();

        return false;
    }
}

/*----------修改资料弹出确定框-------------*/
function release1() {
    document.getElementById("bgback").style.display = "block";
    document.getElementById("popup_btn_box1").style.display = "block";
}

/*---------点击黑色背景时关闭发布--------*/
function offrelease1() {
    document.getElementById("bgback").style.display = "none";
    document.getElementById("popup_btn_box1").style.display = "none";
    //document.getElementById("release1").style.display="none";
    //document.getElementById("release2").style.display="none";

}

/*---------点击确定时修改个人资料--------*/
function offrelease2() {

    param = {
        user_tel: $('#uptel').val(),
        user_addr: $('#upaddr').val(),
        user_name: $('#upname').val(),
        user_photo: $('#user_photo_input').val()
    }
    $.ajax({
        type: 'post',
        data: param,
        dataType: 'text',
        url: '/zgc/index.php/Home/User/update',
        success: function () {

            document.getElementById("bgback").style.display = "none";
            document.getElementById("popup_btn_box1").style.display = "none";

            window.location = '/zgc/index.php/Home/User/user_page';
        }
    })

}

/*----------点击删除图片弹出确定框并赋值-------------*/
var del_id;
function delete_img_tag(m) {
    del_id = m;
    document.getElementById("bgback").style.display = "block";
    document.getElementById("popup_btn_box1").style.display = "block";
}

/*---------点击个人编辑删除按钮时提交资料--------*/
function my_publish_delete() {
    document.getElementById("bgback").style.display = "none";
    document.getElementById("popup_btn_box1").style.display = "none";


    var data = {
        goods_id: del_id,
    }

    $.post('/zgc/index.php/Home/Goods/deletePublish', data, function (msg) {
        if (msg == 1) {
            window.location = '/zgc/index.php/Home/Goods/my_publish_change';
        } else {
            alert('删除失败，请稍候重试！');
        }
    });
}


/*---------点击个人编辑删除按钮时提交资料--------*/
function my_message_delete() {
    document.getElementById("bgback").style.display = "none";
    document.getElementById("popup_btn_box1").style.display = "none";


    var data = {
        goods_id: del_id,
    }

    $.post('/zgc/index.php/Home/Goods/deletePublish', data, function (msg) {
        if (msg == 1) {
            window.location = '/zgc/index.php/Home/Message/my_msg_board';
        } else {
            alert('删除失败，请稍候重试！');
        }
    });


}


/*---------点击取消发布时关闭发布--------*/
function popup_no(x) {
    document.getElementById("bgback").style.display = "none";
    document.getElementById("popup_btn_box1").style.display = "none";
    if (x) {
        window.location = '/zgc/index.php/Home/Goods/my_detail/id/'+x;
    }else{
        window.location = '/zgc/index.php';
    };
    
}


/*---------点击need确定发布时提交资料--------*/
function need_popup_yes() {
    document.getElementById("bgback").style.display = "none";
    document.getElementById("popup_btn_box1").style.display = "none";
}

/*---------保存留言时提交资料--------*/
function save_msg() {
    var data = {
        need_msg_id: $('#goods_id').val(),
        serve_msg_id: $('#serve_id').val(),
        message_content: $('.weui_textarea').val(),
        s_user_id: $('#s_user_id').val()
    };

    $.post('/zgc/index.php/Home/Message/addMessage', data, function (msg) {
        window.location = msg;
    });

}


/*---------返回留言时提交资料--------*/
function backToMsg(m) {
    var serve_id = m;
    var goods_id = $('#need_goods_id').val();

    window.location = '/zgc/index.php/Home/Message/add_msg/goods_id/' + goods_id + '/serve_id/' + serve_id;
    $('.add_serve').hide();
}


/*---------add_msg页面加载完成函数--------*/
function addMsg() {

    var msg = getCookie('msg_name');
    if (msg) {
        $('.weui_textarea').value = msg;

    }

}

/*---------点击添加服务后保存cookie--------*/
function saveCookie() {

    Setcookie('msg_name', $('.weui_textarea').val());
}

/*---------点击serve确定发布时提交资料--------*/


/*------手机验证---------*/
function checkPhone(phone) {

    if (!(/^1[3|4|5|7|8]\d{9}$/.test(phone))) {
        document.getElementById("phone").style.border = "#58749c 2px solid";
        return false;
    }
    document.getElementById("phone").style.border = "none";
    return true;
}

function test(o) {
    document.getElementById("btn1").disabled = false;
    if (checkPhone(document.getElementById("phone").value)) {
        time(o);

        param = {
            phone: $('#phone').val()
        };
        $.ajax({
            type: 'post',
            data: param,
            dataType: 'json',
            url: '/zgc/index.php/Home/User/verify',
            success: function (resp) {
            }
        })
    }

}
var wait = 60;
function time(o) {

    if (wait == 0) {
        o.removeAttribute("disabled");
        o.value = "免费获取验证码";
        wait = 60;
    } else {
        o.setAttribute("disabled", true);
        o.value = "重新发送(" + wait + ")";
        wait--;
        setTimeout(function () {
                time(o)
            },
            1000)
    }
}





function checked1() {
    if (!(document.getElementById("agreement").checked)) {
        document.getElementById("user_agreement1").style.border = "#58749c 2px solid";
        return false;
    }
    else {
        document.getElementById("agreement").style.border = "none";
        return true;
    }
}


function Setcookie(name, value) {

    //设置名称为name,值为value的Cookie
    var expdate = new Date();   //初始化时间
    expdate.setTime(expdate.getTime() + 30 * 60 * 1000);   //时间
    document.cookie = name + "=" + value + ";expires=" + expdate.toGMTString() + ";path=/";

    //即document.cookie= name+"="+alue+";path=/";   时间可以不要，但路径(path)必须要填写，因为JS的默认路径是当前页，如果不填，此cookie只在当前页面生效！~
}


function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end))
        }
    }
    return ""
}

$(function () {
    $(".drop_down_menu2 ul li").click(function () {
        $("#sel1").html($(this).html());
    });
});
$(function () {
    $(".drop_down_menu3 ul li").click(function () {
        $("#sel3").html($(this).html());
    });
});
